let backTT =  function (hook) {
    var footer = [
      '<div id="backToTop">',
      '<span>TOP</span>',
      '</div>'
    ].join('');
    hook.afterEach(function (html) {
      return html + footer;
    });
    hook.doneEach(function () {
      const backTT = document.querySelector('#backToTop')
      let Time1 = null
      let isTop = true
      backTT.addEventListener('click', () => {
        Time1 = setInterval( ()=> {
          let osTop = document.body.scrollTop || document.documentElement.scrollTop;
          let speed = osTop / 5;
          //做一个变换速度的回到顶部效果
          document.documentElement.scrollTop = osTop - speed;
          if (osTop <= 0) {
            //清除定时器
            clearInterval(Time1);
          }
          isTop = true;
        }, 30)
        // document.documentElement.scrollTop = 0
      }, false)
      window.addEventListener('scroll', () => {
        let scrollH = document.documentElement.scrollTop
        if (scrollH > 150) {
          backTT.style.right = '2%'
        } else {
          backTT.style.right = '-5%'
        }
        if (!isTop) {
            clearInterval(Time1);
        }
        isTop = false;
      })
    });
  }